<?php
namespace app\common\model;

use think\Model;

class NewsContent extends Model
{
    public function insert($data = array()){
        if (!is_array($data) || !$data) {
            return 0;
        }
        $data['create_time'] = time();
        if(isset($data['content']) && $data['content']) {
            $data['content'] = htmlspecialchars($data['content']);
        }
        return $this->save($data);
    }
    public function find($id) {
        return $this->where('news_id', $id)->find();
    }
    public function updateNewsById($id, $data){
        if(!$id || !is_numeric($id)) {
            throw_exceptions('ID不合法');
        }
        if(!$data || !is_array($data)) {
            throw_exceptions('副表更新数据不合法');
        }
        if(isset($data['content']) && $data['content']) {
            $data['content'] = htmlspecialchars($data['content']);
        }
        return $this->save($data, ['news_id' => $id]);
    }
}